package com.show.service.message_acessory;

import com.show.util.QueryUtil;
import com.show.dao.message_accessory.MessageAccessorytRepositoty;
import com.show.dto.message_acessory.MessageAccessory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

/**
 * @author 王硕
 * @Param
 * @date 2018-1-29 9:13
 */
@Service
@Transactional
public class MessageAccessoryService {
    @Autowired
    private MessageAccessorytRepositoty messageAccessorytRepositoty;
    @Autowired
    private QueryUtil queryUtil;

    public Integer insertMessageAccessoryt(MessageAccessory messageAccessory){
        try {
            MessageAccessory messageAccessory1=  messageAccessorytRepositoty.save(messageAccessory);
            return messageAccessory1.getAccessoryId();
        }catch (Exception e){
            return -1;
        }

    }
    public void deleteMessageAccessoryt(MessageAccessory messageAccessory){
        messageAccessorytRepositoty.delete(messageAccessory);
    }
    public List<MessageAccessory> getMessageAccessory(String eventId, String accessoryIds){
        String sql = "SELECT * FROM `message_accessory` where event_id = '"+eventId+"' and FIND_IN_SET(accessory_id,'"+accessoryIds+"') ";
        return queryUtil.query(sql,MessageAccessory.class);
    }
}
